package logic

import (
	"context"
	"video/videorpc/videorpcclient"

	"video/api/internal/svc"
	"video/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUpdateLogic) UserUpdate(req *types.UserUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.VideoRpc.UserUpdate(l.ctx, &videorpcclient.UserUpdateRequest{
		Account:   req.Account,
		Password:  req.Password,
		HeadImage: req.HeadImage,
		NickName:  req.NickName,
		UserId:    int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    update,
	}, nil
}
